using UnityEditor;
using UnityEngine;

namespace Duo1JFramework.Actor
{
    [CustomEditor(typeof(BaseActorController), true)]
    public class ActorControllerEditor : BaseCustomEditor<BaseActorController>
    {
        //组件
        private SerializedProperty model;
        private SerializedProperty animator;
        private SerializedProperty footIKCon;
        private SerializedProperty rigidbody;
        private SerializedProperty cc;

        //参数
        private SerializedProperty gravityRate;

        protected override void OnEnable()
        {
            base.OnEnable();

            model = serializedObject.FindProperty("model");
            animator = serializedObject.FindProperty("animator");
            footIKCon = serializedObject.FindProperty("footIKCon");
            rigidbody = serializedObject.FindProperty("rigidBody");
            cc = serializedObject.FindProperty("cc");

            gravityRate = serializedObject.FindProperty("gravityRate");
        }
        protected override void DrawInspector()
        {
            //组件列表
            ED.Vertical(() =>
            {
                GUILayout.Label("组件列表");

                ED.Vertical(() =>
                {
                    ED.Space(3, () =>
                    {
                        EditorGUILayout.ObjectField(model, new GUIContent("模型"));
                        EditorGUILayout.ObjectField(animator, new GUIContent("动画控制器"));
                        EditorGUILayout.ObjectField(footIKCon, new GUIContent("足部IK控制器"));

                        if (rigidbody != null)
                        {
                            EditorGUILayout.ObjectField(rigidbody, new GUIContent("刚体"));
                        }

                        if (cc != null)
                        {
                            EditorGUILayout.ObjectField(cc, new GUIContent("角色控制器"));
                        }
                    });
                }, "box");

                if (GUILayout.Button("一键收集组件"))
                {
                    instance.CollectComponent();
                    EditorUtility.SetDirty(instance);
                }

                GUILayout.Space(5);
                GUILayout.Label("参数列表");

                ED.Vertical(() =>
                {
                    ED.Space(3, () =>
                    {
                        if (gravityRate != null)
                            gravityRate.floatValue = EditorGUILayout.FloatField("重力比率", gravityRate.floatValue);

                        instance.CameraOffsetX = EditorGUILayout.FloatField("相机X轴偏移", instance.CameraOffsetX);
                        instance.CameraOffsetY = EditorGUILayout.FloatField("相机Y轴偏移", instance.CameraOffsetY);
                        instance.CameraOffsetZ = EditorGUILayout.FloatField("相机Z轴偏移", instance.CameraOffsetZ);
                    });
                }, "box");
            });

            GUILayout.Space(5);

            //状态
            ED.Vertical(() =>
            {
                GUILayout.Label("当前状态信息");
                GUILayout.Space(3);
                string info = instance.GetHierarchyInfo();
                GUILayout.TextField(info);
            }, "box");
        }
    }
}
